package com.example.lenovo.demo.presenter;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.StrategyBean;
import com.example.lenovo.demo.presenter.adapter.StrategyChildAcVpAdater;
import com.example.lenovo.demo.view.StrateChildFragment;
import com.example.lenovo.demo.view.ifgview.IStrategyChildActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/15.
 */

public class StrategyChildActivityPresenter implements IStrategyChildActivity {
    private ViewPager viewPager;
    private Context context;
    private ImageView imageView;
    private TextView textView;
    private ProgressDialog dialog;
    private  ArrayList<StrategyBean> data;
    private FragmentManager manager;
    private int numParent,numChild,numTotal;
    private StrategyChildAcVpAdater vpAdater;
    private List<StrateChildFragment> fragments;
    private List<StrategyBean.PagesBean> pagesBeens;
    private String[] names;


    public void initData(){
        dialog.show();
        pagesBeens=new ArrayList<>();
        fragments=new ArrayList<>();

        for (StrategyBean strategyBean : data) {
            pagesBeens.addAll(strategyBean.getPages());
        }
        for (StrategyBean.PagesBean pagesBeen : pagesBeens) {
            fragments.add(StrateChildFragment.getFragment(pagesBeen));
        }
        textView.setText(pagesBeens.get(numTotal).getTitle()+" | "+names[numParent]);
        vpAdater=new StrategyChildAcVpAdater(manager,fragments);
        viewPager.setAdapter(vpAdater);
        viewPager.setCurrentItem(numTotal);
        dialog.dismiss();
    }

    @Override
    public void getView(ViewPager viewPager, Context context, ImageView imageView, TextView textView, ArrayList<StrategyBean> data, FragmentManager manager,ProgressDialog dialog,int numParent,int numChild,int numTotal) {
        this.context=context;
        this.data=data;
        this.imageView=imageView;
        this.textView=textView;
        this.viewPager=viewPager;
        this.manager=manager;
        this.dialog=dialog;
        this.numParent=numParent;
        this.numChild=numChild;
        this.numTotal=numTotal;
        this.names=context.getResources().getStringArray(R.array.names);
    }
}
